package com.hhl;

class ResNumber {

	public int count = 0;

	public static ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>() {
		protected Integer initialValue() {
			return 0;
		};
	};

	public String getNumber() {
		count = threadLocal.get() + 1;
		threadLocal.set(count);
		return count + "";
	}
}

class LocaThreadDemo extends Thread {
	private ResNumber res;

	public LocaThreadDemo(ResNumber res) {
		this.res = res;
	}

	@Override
	public void run() {
		for (int i = 0; i < 3; i++) {
			System.out.println(Thread.currentThread().getName() + "---" 
					+ "i---" + i + "--num:" + res.getNumber());
		}

	}
}

public class ThreadLocaDemo1 {
	public static void main(String[] args) {
		ResNumber res = new ResNumber();
		LocaThreadDemo t1 = new LocaThreadDemo(res);
		LocaThreadDemo t2 = new LocaThreadDemo(res);
		LocaThreadDemo t3 = new LocaThreadDemo(res);
		t1.start();
		t2.start();
		t3.start();
	}
}
